<template>
    <div>
        <el-table row-key="id" :tree-props="{ children: 'children' }" default-expand-all :data="getMenu" border
            style="width: 100%">
            <el-table-column prop="id" label="菜单编号" width="180">
            </el-table-column>
            <el-table-column prop="title" label="菜单名称" width="100">
            </el-table-column>
            <el-table-column prop="pid" label="上级菜单" width="150"> </el-table-column>
            <el-table-column prop="icon" label="菜单图标">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址"> </el-table-column>
            <el-table-column label="状态">
                <!-- 作用域槽口 -->
                <template slot-scope="item">
                    <div>
                        {{ item.row.status == 1 ? '启用' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" size="mini" circle icon="el-icon-edit" @click="edit(item.row.id)">
                        </el-button>
                        <el-button type="danger" size="mini" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex';
import { menuDel } from '../../request/api'
export default {
    computed: {
        ...mapGetters({
            getMenu: 'menu/getMenuList'
        })
    },
    mounted() {
        this.getMenuList()
    },
    methods: {
        ...mapActions({
            getMenuList: 'menu/changeMenuAction'
        }),
        // 封装一个编辑事件告诉父组件打开弹框
        edit(id) {
            this.$emit('edit', id)
        },
        del(id) {
            this.$confirm("你确定要删除这条数据吗", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    menuDel({ id, })
                        .then((res) => {
                            if (res.data.code == 200) {
                                this.$message.success(res.data.msg);
                                //重新触发行动
                                this.getMenuList();
                            } else {
                                this.$message.error(res.data.msg);
                            }
                        })
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                })
        }
    }
};
</script>

<style scoped>
.btn {
    width: 45px;
    height: 30px;
    text-align: center;

}
</style>
